home *** CD-ROM | disk | FTP | other *** search
- /* ToolServer.c: How to create and send an AppleEvent to ToolServer. */
-
- #include <Errors.h>
- #include <Finder.h>
- #include <Strings.h>
- #include <string.h>
-
- #include "ToolServer.h"
- #include "SignatureToApp.h"
-
-
- /* send an Apple event to ToolServer */
-
- OSErr ToolServerCommand(AEDesc *command, CStringHandle *output, CStringHandle *diagnostic,
- AEIdleUPP idleProc, AEFilterUPP filterProc)
- {
- AppleEvent aeEvent, aeReply;
- AEDesc toolServerAddress;
- ProcessSerialNumber toolServerProcess;
- FSSpec appSpec; /* SignatureToApp requires this, documentation to the contrary.... */
- long theLong, theSize;
- DescType theType;
- AEDesc paramDesc;
- OSErr err;
-
- /* default replies */
- *output = NULL;
- *diagnostic = NULL;
-
- /* find the ToolServer */
- err = SignatureToApp(kToolServerCreator, NULL, &toolServerProcess, &appSpec, NULL,
- Sig2App_LaunchApplication, launchContinue + launchDontSwitch);
- if (err != noErr) return err;
- err = AECreateDesc(typeProcessSerialNumber, (Ptr) &toolServerProcess, sizeof(ProcessSerialNumber),
- &toolServerAddress);
- if (err != noErr) return err;
-
- /* Create the ToolServer Apple Event */
- err = AECreateAppleEvent('misc', 'dosc', &toolServerAddress, kAutoGenerateReturnID,kAnyTransactionID,
- &aeEvent);
- AEDisposeDesc(&toolServerAddress);
- if (err != noErr) return err;
-
- /* add the command descriptor to the event */
- err = AEPutParamDesc(&aeEvent, keyDirectObject, command);
- if (err != noErr) { AEDisposeDesc(&aeEvent); return err; }
-
- /* send the apple event */
- err = AESend(&aeEvent, &aeReply, kAEWaitReply + kAENeverInteract, kAENormalPriority,
- kNoTimeOut, idleProc, filterProc);
- AEDisposeDesc(&aeEvent);
- if (err != noErr) return err;
-
- /* check for an error return */
- err = AEGetParamPtr(&aeReply, keyErrorNumber, typeInteger, &theType, &theLong,
- sizeof(long), &theSize);
- if (err != noErr || (err = theLong) != noErr)
- return err;
-
- /* get the command output */
- err = AEGetParamDesc (&aeReply, keyDirectObject, typeChar, ¶mDesc);
- if (err == noErr)
- *output = (CStringHandle)paramDesc.dataHandle;
-
- /* get the diagnostic output */
- err = AEGetParamDesc (&aeReply, 'diag', typeChar, ¶mDesc);
- if (err == noErr)
- *diagnostic = (CStringHandle)paramDesc.dataHandle;
-
- /* get the MPW status -- it becomes our error return */
- err = AEGetParamPtr(&aeReply, 'stat', typeInteger, &theType, &theLong,
- sizeof(long), &theSize);
- if (err == noErr)
- err = theLong;
-
- AEDisposeDesc(&aeReply);
-
- return err;
- }
-